//
//  MovieViewController1.m
//  UI14_豆瓣完整版
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "MovieViewController1.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
#import "UIImageView+WebCache.h"
#import "BYJDataBaseHandle.h"
#import "MovieModel.h"


@interface MovieViewController1 ()

@property (nonatomic, retain) UIScrollView *scrol;


@end

@implementation MovieViewController1

- (void)dealloc {
    [_DIC release];
    [_scrol release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor yellowColor];
    
    self.navigationController.navigationBar.translucent = NO;
    
    self.scrol = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT + 123)];
    
    _scrol.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_scrol];
    [_scrol release];
    
    _scrol.contentSize = CGSizeMake(0, HEIGHT * 5);
    
    // 调用方法
    [self particulars];
    
    self.title = _DIC[@"title"];
}

- (void)particulars {
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = CGRectMake(10, 10, 150, 200);
    imageView.backgroundColor = [UIColor clearColor];
    NSString *str = _DIC[@"images"][@"large"];
    [imageView sd_setImageWithURL:[NSURL URLWithString:str]];
    [_scrol addSubview:imageView];
    [imageView release];
    
    UILabel *gradeLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 15, 40, 30)];
    gradeLabel.backgroundColor = [UIColor clearColor];
    gradeLabel.text = @"评分:";
    [_scrol addSubview:gradeLabel];
    [gradeLabel release];
    
    UILabel *numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(210, 15, 40, 30)];
    numberLabel.backgroundColor = [UIColor clearColor];
    [_scrol addSubview:numberLabel];
    numberLabel.text = _DIC[@"rating"];
    [numberLabel release];
    
    UILabel *gradenumLabel = [[UILabel alloc] initWithFrame:CGRectMake(260, 15, 80, 30)];
    gradenumLabel.backgroundColor = [UIColor clearColor];
    [_scrol addSubview:gradenumLabel];
    [gradenumLabel release];
    
    UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 50, 150, 30)];
    dateLabel.backgroundColor = [UIColor clearColor];
    dateLabel.text = _DIC[@"pubdate"];
    [_scrol addSubview:dateLabel];
    [dateLabel release];
    
    UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 85, 150, 30)];
    timeLabel.backgroundColor = [UIColor clearColor];
    [_scrol addSubview:timeLabel];
    [timeLabel release];
    
    UILabel *typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 120, 150, 30)];
    typeLabel.backgroundColor = [UIColor clearColor];
    [_scrol addSubview:typeLabel];
    [typeLabel release];
    
    UILabel *countryLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 155, 150, 30)];
    countryLabel.backgroundColor = [UIColor clearColor];
    [_scrol addSubview:countryLabel];
    [countryLabel release];
    
    UILabel *producerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 230, 200, 50)];
    producerLabel.backgroundColor = [UIColor clearColor];
    producerLabel.text = @"制作人";
    producerLabel.font = [UIFont systemFontOfSize:25];
    [_scrol addSubview:producerLabel];
    [producerLabel release];
    
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 300, 350, 60)];
    nameLabel.backgroundColor = [UIColor clearColor];
    [_scrol addSubview:nameLabel];
    [nameLabel release];
    
    UILabel *movieLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 370, 200, 50)];
    movieLabel.backgroundColor = [UIColor clearColor];
    movieLabel.text = @"电影情节";
    movieLabel.font = [UIFont systemFontOfSize:25];
    [_scrol addSubview:movieLabel];
    [movieLabel release];
    
    UILabel *storyLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 430, 350, 1000)];
    storyLabel.backgroundColor = [UIColor clearColor];
    [_scrol addSubview:storyLabel];
    [storyLabel release];
    
    // 创建左边按钮
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_nav_back.png"] style:UIBarButtonItemStyleDone target:self action:@selector(itemAction:)];
    self.navigationItem.leftBarButtonItem = item1;
    
    // 创建右侧按钮
    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_nav_share.png"] style:UIBarButtonItemStyleDone target:self action:@selector(itemAction1:)];
    self.navigationItem.rightBarButtonItem = item2;
    
    
}

// 左边按钮的方法
- (void)itemAction:(UIBarButtonItem *)item {
    if (!_b) {
        [self.navigationController popToViewController:self.navigationController.viewControllers[0] animated:YES];
    } else {
        [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
    }
 
}

// 右边按钮方法
- (void)itemAction1:(UIBarButtonItem *)item {
    
    NSMutableArray *arr = [[BYJDataBaseHandle sharedDataBaseHandle] selectMovieTable];
    
    NSMutableArray *titlrArr = [NSMutableArray array];
    for (MovieModel *model in arr) {
        NSString *str = model.title;
        [titlrArr addObject:str];
    }
    
    
    if (![titlrArr containsObject:self.navigationItem.title]) {
        
        MovieModel *model = [MovieModel movieModel];
        
        model.title = self.navigationItem.title;
        
        [[BYJDataBaseHandle sharedDataBaseHandle] insertMovieModel:model];
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"收藏成功" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
        [alert addAction:action];
        
        [self presentViewController:alert animated:YES completion:nil];
        
    } else {
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"已收藏" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
        [alert addAction:action];
        [self presentViewController:alert animated:YES completion:nil];
        
    }
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
